<%@ page language="java" contentType="text/html; charset=UTF-8" %>
<%@ include file="../common.jsp" %>
<%@ include file="../framework/statusbar.jsp" %>
        <!-- Alternative Content Box Start -->
         <div class="contentcontainer">
            <div class="headings altheading">
                <h2><fmt:message key="view.role.list" /></h2>
            </div>
            <div class="contentbox">
            	<form id="form_role_list" action="${_ctx}/user/role-batch.action" method="post">
            	<input type="hidden" id="batchType" name="batchType" value="none" />
				<input type="hidden" name="page.pageNo" id="pageNo" value="${page.pageNo}"/>
				<input type="hidden" name="page.orderBy" id="orderBy" value="${page.orderBy}"/>
				<input type="hidden" name="page.order" id="order" value="${page.order}"/>            	
            	<table id="tb_role_list" width="100%" class="sorter" cellpadding="1" cellspacing="1">
                	<thead>
                    	<tr>
                        	<th id="index" align="center" width="30"><fmt:message key="view.index" /></th>
                            <th id="code" align="center" width="100"><fmt:message key="view.role.code" /></th>
                            <th id="name" align="center" width="150"><fmt:message key="view.role.name" /></th>
                            <th align="center"><fmt:message key="view.role.description" /></th>                            
                            <th align="center" width="40"><fmt:message key="view.operate" /></th>                            
                            <th align="center" width="30"><input type="checkbox" id="checkboxall" value="" name=""></th>
                        </tr>
                    </thead>
                    <tbody>
						<c:forEach items="${page.result}" var="role" varStatus="status">
						<tr class="${status.index % 2 == 1 ? 'alt' : ''}">
							<td  align="center">${status.index+1}</td>
                            <td>${role.code}</td>
                            <td>${role.name}</td>
                            <td>描述</td>
                            <td align="center">
                            	<a id="a_edit_${role.id}"  title="" href="javascript:void(0)"><img alt="<fmt:message key="view.edit" />" src="${_ctx}/resource/img/icons/icon_edit.png"></a>
                                <a id="a_del_${role.id}" title="" href="javascript:void(0)"><img alt="<fmt:message key="view.delete" />" src="${_ctx}/resource/img/icons/icon_delete.png"></a>
                            </td>
                            <td align="center"><input type="checkbox" name="roleIds" value="${role.id}"></td>
						</tr>
						</c:forEach>
                    </tbody>
                </table>
                <div class="extrabottom">
                	<ul>
                    	<li><img alt="<fmt:message key="view.edit" />" src="${_ctx}/resource/img/icons/icon_edit.png"> <fmt:message key="view.edit" /></li>
						<li><img alt="<fmt:message key="view.delete" />" src="${_ctx}/resource/img/icons/icon_delete.png"> <fmt:message key="view.delete" /></li>
                    </ul>
                    <div class="bulkactions">
                    	<select id="batch_action">
                        	<option value="none"><fmt:message key="view.batch.action" /></option>
                        	<option value="delete"><fmt:message key="view.batch.delete" /></option>
                        </select>
                        <input type="submit" id="btn_apply" class="btn" value="<fmt:message key="view.apply" />">
                        &nbsp;
                        <input type="button" id="btn_add_role" class="btn" value="<fmt:message key="view.add" />">
                    </div>
                </div>
				<%@ include file="../page.jsp" %>
                <div style="clear: both;"></div>
                </form>
            </div>
            
        </div>
		<!-- Alternative Content Box End -->

		
	
<script type='text/javascript'>

	$(document).ready(function(){
		//增加
		$("#btn_add_role").click(function() {
			rightside.showEditDialog("${_ctx}/user/role-add-form.action");
		});
		
		
		//修改
		$("a[id^=a_edit_]").each(function() {
			$(this).bind("click", function() {
				var id = $(this).attr("id").substring(7);
				rightside.showEditDialog("${_ctx}/user/role-edit-form.action?roleId=" + id);
			});
		});
		
		
		//删除
		$("a[id^=a_del_]").each(function() {
			$(this).bind("click", function() {
				var id = $(this).attr("id").substring(6);
				rightside.load("${_ctx}/user/role-delete.action?roleId=" + id);
			});
		});

		//全选
		$("#checkboxall").click(function() {
			var checked_status = this.checked;
			$("input[name=roleIds]").each(function() {
				this.checked = checked_status;
			});
		});
		
		//批量操作提交
		$("#form_role_list").ajaxForm({
			beforeSubmit : function() {
				if($("#batch_action").val() == 'none') {
					alert("<fmt:message key='view.batch.choose' />");
					return false;
				}
				else {
					if($("input[name=roleIds]").filter(":checked").size() == 0) {
						alert("<fmt:message key='view.batch.type' />");
						return false;
					}
					return true;
				}
			},
			success : function(data) {
				rightside.html(data);
			}
		});
		
		
		$("#batch_action").change(function(){
			$("#batchType").val($("#batch_action").val());
		});
		
		
		$("#tb_role_list").tablesorter({
			headers: {
				0: {sorter: false},
				3: {sorter: false},
				4: {sorter: false},
				5: {sorter: false}
			}
		});
		
	});

	
	function jumpPage(jumpNo) {
		$("#pageNo").val(jumpNo);
		var queryString = $('#form_role_list').formSerialize();
		rightside.load("${_ctx}/user/role-list.action?1=1&" + queryString);
	}
</script>